package com.example.activiti.demo.util;

import com.example.activiti.demo.entity.SysUser;
import org.activiti.engine.identity.Group;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.activiti.engine.impl.persistence.entity.GroupEntityImpl;
import org.activiti.engine.impl.persistence.entity.UserEntity;
import org.activiti.engine.impl.persistence.entity.UserEntityImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author: cheng
 * @date: 2020/2/21 17:10
 */
public class ActivitiUserUtil {
    public static UserEntity toActivitiUser(SysUser sysUser) {
        UserEntity userEntity = new UserEntityImpl();
        userEntity.setId(sysUser.getId());
        userEntity.setFirstName(sysUser.getUsername());
        userEntity.setLastName(sysUser.getRealName());
        userEntity.setPassword(sysUser.getPassword());
        userEntity.setEmail(sysUser.getEmail());
        userEntity.setRevision(1);
        return userEntity;
    }

    public static GroupEntity toActivitiGroup(String code) {
        GroupEntity groupEntity = new GroupEntityImpl();
        groupEntity.setRevision(1);
        groupEntity.setType("assignment");
        groupEntity.setId(code);
        return groupEntity;
    }

    public static List<Group> toActivitiGroups(List<String> roleCodeList) {
        List<Group> groups = new ArrayList<Group>();
        for (String code : roleCodeList) {
            GroupEntity groupEntity = toActivitiGroup(code);
            groups.add(groupEntity);
        }
        return groups;
    }
}
